<%-- 
    Document   : upload
    Created on : Jul 2, 2012, 5:48:21 PM
    Author     : Home
--%>


<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page import="org.apache.commons.fileupload.FileItem"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.io.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%

    String url = "";
    try {
        
        DiskFileUpload fu = new DiskFileUpload();
        fu.setSizeMax(1000000);

        List fileItems = fu.parseRequest(request);
        Iterator itr = fileItems.iterator();

        while (itr.hasNext()) {
            FileItem fi = (FileItem) itr.next();

            if (!fi.isFormField()) {
                
                url = fi.getName().toString();
                String savePath=request.getRealPath("/")+"media\\";
                System.out.println(savePath);
                File fNew = new File(savePath + fi.getName());
                fi.write(fNew);
                
            } else {
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

%>
<html>
<body>
    <h3>Upload Successful file : <% out.print(url);%></h3>
    <br/>
    <input type="button" value="Close window" onclick="window.opener.document.f1.imgs.value='media/<% out.print(url);%>';window.close();" />
</body>
</html>
